﻿package com.saint.bitmapDistortion.tests 
{
	import com.saint.bitmapDistortion.IStretchyImage;
	import com.saint.bitmapDistortion.StretchyImage;
	import com.saint.bitmapDistortion.StretchyImageAnimator;
	import com.saint.utils.Logger;
	import flash.display.MovieClip;
	import flash.display.DisplayObject;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	/**
	 * ...
	 * @author kembera
	 */
	public class StretchyImageTest extends Sprite
	{
	
		private var stretchyImage:IStretchyImage;
		private var stretchyAnimator:StretchyImageAnimator;
		private var resetButton:MovieClip;
		
		
		public function StretchyImageTest(stage:Stage) 
		{
			Logger.info("StretchyImageTest.StretchyImageTest");
			
			stretchyImage = new StretchyImage(new Goat(), 6, 6);
			stretchyImage.x = 100;
			stretchyImage.y = 20;
			stage.addChild(DisplayObject(stretchyImage));
			stretchyImage.init();
			
			/*reset button*/
			resetButton = new ResetButton();
			resetButton.x = 0;
			resetButton.y = 450;
			resetButton.alpha = 0.9;
			resetButton.addEventListener(MouseEvent.CLICK, reset);
			resetButton.mouseChildren = false;
			stage.addChild(resetButton);			
			
			/* stretchy Image animation */
			stretchyAnimator = new StretchyImageAnimator();		
			
			stage.addEventListener(MouseEvent.CLICK, doTest);
		}
		
			
		private function reset(e:MouseEvent):void
		{
			Logger.info("Main.reset");		
			stretchyImage.reset();		
		}
		
				
		private function doTest(e:MouseEvent):void 
		{
			Logger.info("Main.doSuckToPointTest " + e.target);		
			
			/* hack to srop invisible buttons triggering the animation */
			if (e.target.alpha == 1)
			{		
				
				/* suck to point test */
				var targetPoint:Point = new Point(e.stageX, e.stageY);			
				stretchyAnimator.animateImage(stretchyImage, StretchyImageAnimator.SUCK_TO_POINT, { point:targetPoint, time:0.5 } );

			}
			
		}
		
	}

}